package be.destin.memolog;

import be.destin.memo.Comment;
import be.destin.memo.DisplayDetail;
import be.destin.memo.DisplayLog;
import be.destin.memo.Log;
import be.destin.memo.ReadDetail;
import be.destin.memo.ReadLog;
import be.destin.memo.SearchDetail;
import be.destin.memo.SearchLog;
import be.destin.memo.TagDef;
import be.destin.memo.Tagged;
import be.destin.memo.UpdateDetail;
import be.destin.memo.UpdateLog;

public enum UsageMode {
	DISPLAY, READ, UPDATE, SEARCH, COMMENT, TAGDEF,TAGGED;
	
	private static Class[] detailClasses = {DisplayDetail.class, ReadDetail.class, UpdateDetail.class, SearchDetail.class,null,null};
	private static Class[] logClasses = {DisplayLog.class, ReadLog.class, UpdateLog.class, SearchLog.class,Comment.class,TagDef.class,Tagged.class};
 	
	public String getNiceName() {
		return Character.toUpperCase(this.name().charAt(0)) + this.name().substring(1).toLowerCase();
	}

	public Class getDetailClass() {
		return detailClasses[this.ordinal()];
	}

	public Class getLogClass() {
		return logClasses[this.ordinal()];
	}
	
	public static UsageMode findLogClass(Log entity) {
		int i = 0;
		for (Class<Log> aClass : logClasses) {
			if (entity.getClass() == aClass) break;
			i++;
		}
		if (i<logClasses.length) {
			return UsageMode.values()[i];
		}
		return null;
	}
}
